package com.muk.meis.controller.question;

import java.io.IOException;
import java.util.Date;

import javax.servlet.Servlet;
import javax.servlet.annotation.WebServlet;

import com.muk.meis.model.bean.Answer;
import com.muk.meis.model.bean.Question;
import com.muk.meis.model.service.AnswerService;
import com.muk.meis.model.service.QuestionService;
import com.muk.webframework.framework.controller.BaseController;

/**
 * Servlet implementation class QuestionController
 */
@WebServlet("/QuestionController/*")
public class QuestionController extends BaseController implements Servlet {
	private static final long serialVersionUID = 1L;

    public QuestionController() {
    }
    
    public void create() throws IOException{
    	String questionMessage = request.getParameter("question");
    	String percodeCode = request.getParameter("percode");
    	String postBy = request.getParameter("postBy");
    	Question question = new Question();
    	question.setQuestion(questionMessage);
    	question.setPercodeCode(percodeCode);
    	question.setPostBy(postBy);
    	question.setCreateDate(new Date());
    	
    	QuestionService service = new QuestionService();
    	service.create(question);
    	response.sendRedirect(request.getContextPath()+"/school/listnews.jsp?percode="+percodeCode+"#tabs-5");
    }
    
    public void update() throws IOException{
    	String answerMessage = request.getParameter("answer_message");
    	String postBy = request.getParameter("post_by");
    	String questionId = request.getParameter("questionId");
    	String percode = request.getParameter("percode");
    	
    	Answer answer = new Answer();
    	answer.setPostBy(postBy);
    	answer.setMessage(answerMessage);
    	answer.setQuestionId(Integer.parseInt(questionId));
    	
    	AnswerService service = new AnswerService();
    	service.create(answer);
    	response.sendRedirect(request.getContextPath()+"/question/edit.jsp?percode="+percode+"&questionId="+questionId+"#tabs-5");
    }

}
